﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 习题2._3_OldBill_CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string line;
            while ((line = Console.ReadLine()) != null)
            {
                string line2 = Console.ReadLine();
                string[] token = line.Split();
                string[] token2 = line2.Split();
                int n = Convert.ToInt32(line);
                int x = Convert.ToInt32(token2[0]);
                int y = Convert.ToInt32(token2[1]);
                int z = Convert.ToInt32(token2[2]);

                List<Tuple<int, int, int>> tuples = new List<Tuple<int, int, int>>();   //对应 万、个、单价
                for (int i = 1; i <= 9; i++)    //万位不为0
                {
                    for (int j = 0; j <= 9; j++)    //个位可为0
                    {
                        int totalPrice = i * 10000 + x * 1000 + y * 100 + z * 10 + j;
                        if (totalPrice % n == 0)
                        {
                            //Tuple<int, int, int> tuple = new Tuple<int, int, int>(i, j, totalPrice);
                            tuples.Add(new Tuple<int, int, int>(i, j, totalPrice/n));
                        }
                    }
                }
                //Tuple<int, int, int> tuple_min = tuples.Min();
                //Tuple<int, int, int> tuple = tuples.Max();
                if (tuples.Count == 0)
                {
                    Console.WriteLine(0);
                }
                else
                {
                    Tuple<int, int, int> tuple = tuples.Max();
                    Console.WriteLine($"{tuple.Item1} {tuple.Item2} {tuple.Item3}");        //虽然还是没完全弄懂，List对于最大最小调用方法的原理，不过还是勉强通过了这个测试。感觉不够严谨
                }
            }
        }
    }
}
